package com.brainydroid.example.numerical_distance;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.brainydroid.framework.Scene;


public class sd2data {

	public static Result loaddata() throws IOException{
		// DO some little stats

		if (Gdx.files.isExternalStorageAvailable()) {

			File dir = new File(Gdx.files.getExternalStoragePath()  + "/Experiment");
			dir.mkdirs();


			File file = new File(dir, "data.txt");

			FileInputStream f = new FileInputStream(file);


			InputStreamReader in = new InputStreamReader(f);
			BufferedReader breader = new BufferedReader(in);

			String Line;

			breader.readLine(); // skip header

			Line = breader.readLine();
			String items[] = new String[3];

			ArrayList<Integer> numbers = new ArrayList<Integer>(); 
			ArrayList<Integer> answers = new ArrayList<Integer>(); 
			ArrayList<Float> delays = new ArrayList<Float>(); 


			while(Line != null){

				items = Line.split("\t");
				numbers.add((int)Float.parseFloat(items[0]));
				answers.add((int)Float.parseFloat(items[1]));
				delays.add(Float.parseFloat(items[2]));

				Line = breader.readLine();
			}

			breader.close(); in.close(); f.close();


			return new Result(numbers,answers,delays);
		}
		return null;
		
	}


}
